#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    string replaceSpaces(string S, int length) {
        string ret;
        for (int i = 0; i < length; i++)
        {
            if (' ' == S[i])
                ret += "%20";
            else
                ret += S[i];
        }
        return ret;
    }
};